<?php
/**
 * 修复commnetLink 表中的res_id
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\wiki\ObjRelateWiki as sObjRelateWiki;
use Doraemon\model\CommentLink;
use Doraemon\service\Comment;

$num = 0;
if (isset($argv[1])) {
    $num = $argv[1];
}

$startTime = strtotime('2019-06-17');
$sql = "SELECT * FROM " . CommentLink::getTableName() . " WHERE `uid` >0 and `uid`=`ouid` and `res_id`=0 and `status`!=9 and `addtime`> " . $startTime;
$list = [];
$page = 1;
$pageSize = 1000;
do {
    $limit = ($page - 1) * $pageSize;
    $sql = $sql . " ORDER BY `id` DESC " . " LIMIT " . $limit . " , " . $pageSize;
    $list = CommentLink::query($sql)->fetchAll();
    if ($list) {
        foreach ($list as $value) {
            var_dump('分析数据Id:' . $value['id']);
            try {
                sObjRelateWiki::commentRelateWiki($value['ouid'], $value['obj_id'], Comment::getCommentRelateWikiType($value['obj_id']), $value['comments_id'], $value['origin_link']);
            } catch (\Exception $e) {
                var_dump($e->getMessage());
            }
        }
    }
    $page++;
} while ($list);